﻿using SBlogCore.Entitys.SysRoleManager;

namespace SBlogCore.Entitys.SystemManager
{
    public class SysMenu : DeleteEntity, IEntityTypeConfiguration<SysMenu>
    {
        /// <summary>
        /// 当设置 redirect 的时候该路由在面包屑导航中不可被点击
        /// </summary>
        [Comment("定向地址")]
        public string? Redirect { get; set; }
        /// <summary>
        /// 除了 layout 对应的 path 前面需要加 /，其余子路由都不要以/开头
        /// </summary>
        [Comment("路径")]
        public string? Path { get; set; }
        /// <summary>
        /// 路由Name不能重复
        /// </summary>
        [Comment("名称")]
        public string? Name { get; set; }

        [Comment("源文件地址")]
        public string? Component { get; set; }

        [Comment("层级")]
        public int Level { get; set; }

        [Comment("标题")]
        public string? Title { get; set; }

        [Comment("图标")]
        public string? Icon { get; set; }

        [Comment("排序")]
        public int Order { get; set; }

        /// <summary>
        /// 当设置 true 的时候该路由不会再侧边栏出现 如404，login等页面(默认 false)
        /// </summary>
        [Comment("是否隐藏")]
        public bool? Hidden { get; set; }
        /// <summary>
        /// 是否在左侧显示根目录
        /// </summary>
        [Comment("是否在左侧显示")]
        public bool? AlwaysShow { get; set; }
        [Comment("keep-alive缓存")]
        public bool? NoCache { get; set; }
        [Comment("是否在面包屑中显示")]
        public bool? Breadcrumb { get; set; }
        [Comment("是否固定在Tag上")]
        public bool? Affix { get; set; }
        [Comment("是否不在Tag中显示")]
        public bool? NoTagsView { get; set; }
        [Comment("显示高亮的路由路径")]
        public string? ActiveMenu { get; set; }
        [Comment("跟随那个路由进行权限过滤")]
        public string? FollowAuth { get; set; }
        [Comment("是否允许跳转")]
        public bool? CanTo { get; set; }
        /// <summary>
        /// 是否为父级
        /// </summary>
        [Comment("是否为父级")]
        public bool? IsParent { get; set; }

        [Comment("父级")]
        public long? ParentInfoId { get; set; }

        public SysMenu? ParentInfo { get; set; }

        public List<SysMenu>? ChildrenList { get; set; } = new List<SysMenu>();

        /// <summary>
        /// 多对多中间表（用户角色）
        /// </summary>
        [Comment("多对多中间表（用户角色）")]
        public List<SysRoleMenu>? SysRoleMenus { get; set; }
        /// <summary>
        /// 角色
        /// </summary>
        public List<SysRoleInfo>? SysRoles { get; set; }

        public void Configure(EntityTypeBuilder<SysMenu> builder)
        {
            builder.HasOne(s => s.ParentInfo).WithMany(s => s.ChildrenList);
            //创建种子数据
            builder.HasData(
                new SysMenu()
                {
                    Id = 361843685175365,
                    Redirect = "/System/SysMenuManager",
                    Path = "/System",
                    Name = "System",
                    Component = "#",
                    SysOrgId = 142307070910552,
                    CreatedTime = DateTimeOffset.Now,
                    CreatedUserId = 142307070910551,
                    Level = 0,
                    Icon = "el-icon-s-tools",
                    Title = "系统管理",
                    Order = 3,
                    Affix = false,
                    AlwaysShow = true,
                    Breadcrumb = true,
                    CanTo = false,
                    Hidden = false,
                    NoCache = false,
                    NoTagsView = false,
                    IsParent = true
                },
                new SysMenu()
                {
                    Id = 361844436615237,
                    Path = "SysMenuManager",
                    Name = "SysMenuManager",
                    Component = "system/SysMenuManager/Index",
                    SysOrgId = 142307070910552,
                    CreatedTime = DateTimeOffset.Now,
                    CreatedUserId = 142307070910551,
                    Level = 1,
                    ParentInfoId = 361843685175365,
                    Icon = "el-icon-s-fold",
                    Title = "菜单管理",
                    Order = 0,
                    Affix = false,
                    AlwaysShow = false,
                    Breadcrumb = true,
                    CanTo = false,
                    Hidden = false,
                    NoCache = false,
                    NoTagsView = false
                },
                new SysMenu()
                {
                    Id = 366269923790917,
                    Path = "SysUserManager",
                    Name = "SysUserManager",
                    Component = "system/SysUserManager/Index",
                    SysOrgId = 142307070910552,
                    CreatedTime = DateTimeOffset.Now,
                    CreatedUserId = 142307070910551,
                    Level = 1,
                    ParentInfoId = 361843685175365,
                    Icon = "el-icon-user-solid",
                    Title = "用户管理",
                    Order = 0,
                    AlwaysShow = false,
                    Hidden = false,
                    NoCache = false
                },
                new SysMenu()
                {
                    Id = 366358749757509,
                    Path = "SysOrgInfoManager",
                    Name = "SysOrgInfoManager",
                    Component = "system/SysOrgInfoManager/Index",
                    SysOrgId = 142307070910552,
                    CreatedTime = DateTimeOffset.Now,
                    CreatedUserId = 142307070910551,
                    Level = 1,
                    ParentInfoId = 361843685175365,
                    Icon = "el-icon-menu",
                    Title = "组织架构",
                    Order = 0,
                    AlwaysShow = false,
                    Hidden = false,
                    NoCache = false
                },
                new SysMenu()
                {
                    Id = 367057077911621,
                    Path = "SysFileManager",
                    Name = "SysFileManager",
                    Component = "system/SysFileManager/Index",
                    SysOrgId = 142307070910552,
                    CreatedTime = DateTimeOffset.Now,
                    CreatedUserId = 142307070910551,
                    Level = 1,
                    ParentInfoId = 361843685175365,
                    Icon = "el-icon-folder-opened",
                    Title = "文件管理",
                    Order = 0,
                    AlwaysShow = false,
                    Hidden = false,
                    NoCache = false
                },
                new SysMenu()
                {
                    Id = 367057681936453,
                    Path = "SysRoleManager",
                    Name = "SysRoleManager",
                    Component = "system/SysRoleManager/Index",
                    SysOrgId = 142307070910552,
                    CreatedTime = DateTimeOffset.Now,
                    CreatedUserId = 142307070910551,
                    Level = 1,
                    ParentInfoId = 361843685175365,
                    Icon = "el-icon-user",
                    Title = "角色管理",
                    Order = 0,
                    AlwaysShow = false,
                    Hidden = false,
                    NoCache = false
                });
        }
    }
}

